﻿using System;
using System.Collections.Generic;
using System.Text;
using DreamShield.Deployment.Installers.DreamWorker.PluginsInterfaces;
using DreamShield.Deployment.Package;

namespace DreamShield.Deployment.Miles
{
    /// <summary>
    /// Plugin de base Miles
    /// </summary>
    public interface IMilesPlugin
    {
        /// <summary>
        /// Infrastucture DreamShield
        /// </summary>
        Guid NativePluginType { get; }

        /// <summary>
        /// Infrastucture DreamShield
        /// </summary>
        IDreamShield_Plugin NativePluginImplementation { get; }
    }

    /// <summary>
    /// Classe de base pour les plugins miles
    /// </summary>
    public abstract class BaseMilesPlugin : IMilesPlugin
    {
        /// <summary>
        /// Server Miles en cours
        /// </summary>
        public virtual MilesRootServer Server { get; protected set; }

        /// <summary>
        /// Package d'installation actuel
        /// </summary>
        public virtual InstallationPackage CurrentPackage
        {
            get { return Server.Engine.Package; }
        }

        /// <summary>
        /// Construit une nouvelle instance d'un plugin de base Miles
        /// </summary>
        /// <param name="server">Serveur de plugins correspondant</param>
        public BaseMilesPlugin(MilesRootServer server)
        {
            if (server == null)
                throw new ArgumentNullException("server");

            Server = server;
        }


        #region Infrastucture

        /// <summary>
        /// Guid de plugin natif
        /// </summary>
        protected virtual Guid _NativePluginType { get; set; }
        /// <summary>
        /// Guid de plugin natif
        /// </summary>
        public virtual Guid NativePluginType
        {
            get { return _NativePluginType; }
        }

        /// <summary>
        /// Implémentation native du plugin
        /// </summary>
        protected virtual IDreamShield_Plugin _NativePluginImplementation { get; set; }

        /// <summary>
        /// Implémentation native du plugin
        /// </summary>
        public virtual IDreamShield_Plugin NativePluginImplementation
        {
            get { return _NativePluginImplementation; }
        }

        #endregion

        /// <summary>
        /// Variables globales de l'installeur
        /// </summary>
        public virtual Dictionary<string, object> GlobalInstallerVariables
        {
            get { return Server.Engine.Package.InstanceVariables; }
        }
    }
}
